#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename:   01-service-run.sh
# Version:    1.0
# Date:       2020/07/08
# Author:     Lz
# Email:      lz843723683@gmail.com
# History：     
#             Version 1.0, 2020/07/08
# Function:   服务器运行版-默认服务和软件包
# Out:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
SvcClean_FTLYY_RUN(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
SvcExit_FTLYY_RUN(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
SvcUSAGE_FTLYY_RUN(){
	USAGE_FTLIB "联研院服务器运行版 - 服务器运行版"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
SvcInit_FTLYY_RUN(){
        # 调用初始化函数
	Init_FTLIB "SvcClean_FTLYY_RUN"
        # 调用用户界面函数
 	SvcUSAGE_FTLYY_RUN
}


## TODO ：默认开启服务：psacct、network、firewalld、crond、cups、auditd、rsyslog、smartd、sysstat、acpid
#
SvcTest01_FTLYY_RUN(){
        local svcArr="psacct network firewalld crond cups auditd rsyslog smartd sysstat acpid"

        SvcActiveArr_FTLIB "isActive" "no" "$svcArr"
        RetParse_FTLIB "要求已经激活以下服务 ${svcArr}" "False"

        SvcEnableArr_FTLIB "isEnable" "no" "$svcArr"
        RetParse_FTLIB "要求开机自启动以下服务 ${svcArr}" "False"
}


## TODO ：默认关闭sshd服务
#
SvcTest02_FTLYY_RUN(){
        local svcname="sshd"

        # 判断服务是否激活
        SvcActive_FTLIB "noActive" "no" "${svcname}"
        RetParse_FTLIB "已关闭 ${svcname} 服务" "False"

        # 开机自启动
        SvcEnable_FTLIB "noEnable" "no" "${svcname}"
        RetParse_FTLIB "开机无需自启动 ${svcname} 服务" "False"
}


## TODO ：默认安装:acl attr bash coreutils crontabs e2fsprogs expect file findutils gawk gdb glibc grep grub2-common gzip iproute iptables iputils kbd less libaio libcap libgcc libmac libpcap libstdc++ libusb logrotate kmod ncurses net-tools ntp openssl dpkg procps-ng psmisc readline sed sqlite libsysfs rsyslog sysvinit-tools tar tcpdump time libgudev1 unixODBC util-linux vim wget zlib"
#
SvcTest03_FTLYY_RUN(){
	local pkgArr="acl attr bash coreutils crontabs e2fsprogs expect file findutils gawk gdb glibc grep grub2-common gzip iproute iptables iputils kbd less libaio libcap libgcc libmac libpcap libstdc++ libusb logrotate kmod ncurses net-tools ntp openssl dpkg procps-ng psmisc readline sed sqlite libsysfs rsyslog sysvinit-tools tar tcpdump time libgudev1 unixODBC util-linux wget zlib"

	PkgExistArr_FTLIB "isExist" "no" "yes" "$pkgArr"
	RetParse_FTLIB "要求默认安装：${pkgArr}" "False"
	
	# 模糊匹配
	local pkgname="vim"
	PkgExist_FTLIB "isExist" "no" "no" "${pkgname}"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
SvcMain_FTLYY_RUN(){
	SvcInit_FTLYY_RUN

	SvcTest01_FTLYY_RUN

	SvcTest02_FTLYY_RUN

	SvcTest03_FTLYY_RUN

	return ${TPASS}	
}

SvcMain_FTLYY_RUN
SvcExit_FTLYY_RUN $?
